//2009/09/02 12:19:29
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class BinaryCardinality
{
public:
    vector <int> arrange(vector <int> numbers)
    {
        vector<pair<int, pair<int, int> > > v(numbers.size());
        for (int i=0; i<numbers.size(); i++)
        {
            v[i].first = count(numbers[i]);
            v[i].second.second = i;
            v[i].second.first = numbers[i];
        }
        sort(v.begin(), v.end());
        vector<int> ret;
        for (int i=0; i<numbers.size(); i++)
            ret.push_back(v[i].second.first);
        return ret;
    }
    int count (int n)
    {
        int ret = 0;
        while (n > 0)
        {
            if (n % 2 == 1) ret ++;
            n /= 2;
        }
		cout << ret << endl;
        return ret;
    }
};
